﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PhantomMvvmToolkit;

namespace PhantomMvvmToolkitTester
{
    /// <summary>
    /// This is an example file used to show syntax and standard useage.
    /// </summary>
    public class Examples : IPhantomCommand, IPhantomNotifyPropertyChanged
    {
        #region Code Examples

        public void DelayWhileProcessingExample()
        {
            //in this example the PropertyChagned event would only raise once for "AnInt" and "AnotherInt" once this using is closed.
            //The order of operations would make "AnotherInt" first then "AnInt" next.  The order of operation is based on first in first out, but
            //if one property is repeated like above, it will be moved to the last spot in the queue.

            using (this.DelayNotifyEvents())
            {
                //Place any processing code here that would cause update events to PropertyChanged

                this.AnInt = 10;
                this.OnPropertyChanged("AnInt");

                this.AnInt = 20;
                this.OnPropertyChanged("AnInt");

                this.AnotherInt = 10;
                this.OnPropertyChanged("AnotherInt");

                this.AnInt = 30;
                this.OnPropertyChanged("AnInt");

                this.AnInt = 40;
                this.OnPropertyChanged("AnInt");

                this.AnInt = 50;
                this.OnPropertyChanged("AnInt");

                this.AnInt = 60;
                this.OnPropertyChanged("AnInt");

                this.AnotherInt = 20;
                this.OnPropertyChanged("AnotherInt");

                this.AnInt = 70;
                this.OnPropertyChanged("AnInt");

                this.AnInt = 80;
                this.OnPropertyChanged("AnInt");
            }
        }

        public void CrossThreadSafetyExample()
        {
            //This will cause all PropertyChagned and CanExecuteChanged events to be rerouted to the dispatcher inside this using statement.

            using (this.ThreadSafeNotifyEvents())
            {
                //Place any model or view model updates in here that come from another thread to prevent CrossThreadViolation exceptions.

                this.AnInt = 20;
                this.OnPropertyChanged("AnInt");

                this.AnotherInt = 10;
                this.OnPropertyChanged("AnotherInt");
            }
        }

        public void ExtensionOverrides()
        {
            //basic raise event, default to Normal change type and EventArg.Empty
            this.OnCanExecuteChanged();

            //basic raise event, default to Normal change type
            this.OnPropertyChanged("PropertyName");

            //Forces Cross Thread Safe processing);
            this.OnCanExecuteChanged(ChangedEventType.CrossThreadSafe);
            this.OnPropertyChanged("PropertyName", ChangedEventType.CrossThreadSafe);

            //Forces it to ignore any delay commands
            this.OnCanExecuteChanged(ChangedEventType.IgnoreDelay);
            this.OnPropertyChanged("PropertyName", ChangedEventType.IgnoreDelay);

            //Forces it to use both ingore delay and cross thread safe actions
            this.OnCanExecuteChanged(ChangedEventType.CrossThreadSafe | ChangedEventType.IgnoreDelay);
            this.OnPropertyChanged("PropertyName", ChangedEventType.CrossThreadSafe | ChangedEventType.IgnoreDelay);
        }

        #endregion

        //Just simple properties to allow this code file to build.
        #region Properties

        public int AnInt { get; set; }
        public int AnotherInt { get; set; }

        #endregion

        //Interface methods left with NotImplementedException as this is just an code example file.
        #region Interface Methods and Events

        public void InvokeCanExecuteChanged(EventArgs args)
        {
            throw new NotImplementedException();
        }

        public bool CanExecute(object parameter)
        {
            throw new NotImplementedException();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            throw new NotImplementedException();
        }

        public void InvokePropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
        {
            throw new NotImplementedException();
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
